<?php

class php
{
    private int $num;
    protected ?float $version;
    public string $name;
    public array $numList = [2,3,4];

    public function __construct(int $num, $version, $name)
    {
        $this->num = $num;
        $this->version = $version;
        $this->name = $name;
    }

    public function getVersion():?float
    {
        return $this->version;
    }

    //php7 不确定参数
    public function getTotalNum(int $one, int $two, int ...$params):int
    {   
        //$paramsArray = $params; 组成一个数组
        return $this->num += $one + $two + array_sum($params);
    }

    //7.4
    public function newFeatureFun():void
    {   

        //$one['num'] = $one['num'] ?? 10;
        $one['num'] ??= 10; 

        // array_map(function(){}, [])
        $newNum = array_map(fn($val) => $val + $one['num'], $this->numList);

        var_dump($newNum);// [12 13 14]

    }
}

//$p = new php(10, 7.4, 'php7.4');  // ok
//$p = new php(10, '7.4', 'php7.4'); // ok
//$p = new php(10, 7, 'php7.4');//ok
//$p = new php(10, null, 'php7.4');//ok

//$p = new php(10, 'php', 'php7.4');// error

//$p = new php(10, 7.4, 7);//ok
//$p = new php(10, 7.4, null);// error

// 说明 php int | float 虽然声明了强制类型 ，但是也没有要求 那么严格 ，注意 但用时 10.42 会自动转化成 10
$p = new php(10.42, 7.4, 'php7.4');// ok
//echo $p->getTotalNum(0, 0);

//$p->newFeatureFun();
echo $p->getVersion();